﻿using System;
using System.Linq;
using System.Linq.Expressions;
using Budget.Core.DomainModel;
using Budget.Core.Specifications.Base;

namespace Budget.Core.Specifications
{
    internal class LastBalanceSpecification : Specification<Balance>
    {
        protected override Expression<Func<Balance, bool>> Predicate
        {
            get { return balance => true; }
        }

        public override IQueryable<Balance> SatisfyFrom(IQueryable<Balance> candidates)
        {
            var ordered = candidates.OrderByDescending(balance => balance.CreationDate);

            return base.SatisfyFrom(ordered);
        }
    }
}